import 'package:flutter/material.dart';
import 'package:proj_shop/roots/tutorial/navigator_service.dart';
import 'package:proj_shop/roots/tutorial/pages/tutorial_page1.dart';
import 'package:proj_shop/roots/tutorial/pages/tutorial_page2.dart';
import 'package:proj_shop/roots/tutorial/pages/tutorial_page3.dart';
import 'package:proj_shop/roots/widget/tutorial_update_dialog.dart';

class TutorialApp extends StatefulWidget {
  @override
  _TutorialAppState createState() => _TutorialAppState();
}

class _TutorialAppState extends State<TutorialApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    //updateAlert(context);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Widget',
      themeMode: ThemeMode.dark,
      theme: _appThemeData(),
      onGenerateRoute: generateRoute,
      navigatorKey: NavigatorService().navigatorKey,
    );
  }

  Route generateRoute(RouteSettings routeSettings) {
    switch (routeSettings.name) {
      case '/page2':
        return MaterialPageRoute(
          builder: (_) => TutorialPage2(
            inputParams: routeSettings.arguments,
          ),
        );
      case '/page3':
        return MaterialPageRoute(builder: (_) => TutorialPage3());
      default:
        return MaterialPageRoute(builder: (_) => TutorialPage1());
    }
  }

  // 设置APP主题色
  ThemeData _appThemeData() {
    return ThemeData(
      primaryColor: Colors.blueAccent[400],
      accentColor: Colors.amber[500],
      canvasColor: const Color(0xFFF8F8F8),
    );
  }
}

// Future<void> updateAlert(BuildContext context) async {
//   Future.delayed(Duration(seconds: 2)).then((value) {
//     // 显示升级弹窗
//     showDialog(
//       context: context,
//       barrierDismissible: false, // 点击空白区域对话框不消失
//       builder: (_) {
//         return WillPopScope(
//           child: TutorialUpdateDialog(),
//           onWillPop: () {
//             return;
//           },
//         );
//       },
//     );
//   });
// }
